<template>
  <div id="cesiumContainer" ref="cesiumContainer"></div>
</template>

<script setup>
import { onMounted, ref } from 'vue'
import * as Cesium from 'cesium'
import "./Widgets/widgets.css"
// 设置静态资源路径
window.CESIUM_BASE_URL = "/"

Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJjZTkyZDVmZS03MGNiLTQ4YmQtYTUwMS02YTI0Y2E4OTE2YjciLCJpZCI6MjY1MjI2LCJpYXQiOjE3MzUyODM3MDJ9.HX2jU9DxJdbu9WYQW9iFkLTvSgJtTnBehN89Da7ImUw'

// 设置cesium默认视角
Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees(
  89.5,  //西边经度
  20.4,   //南边纬度
  110.4,  //东边经度
  61.2  //北边纬度
)

onMounted(() => {
  console.log(Cesium)
  var token = 'ee20013ff03e7d98b23e1251bc0b7cea';
  var tdtUrl = 'https://t{s}.tianditu.gov.cn/';
  var subdomains = ['0', '1', '2', '3', '4', '5', '6', '7'];
  const viewer = new Cesium.Viewer('cesiumContainer', {
    // 是否显示信息窗口
    infoBox: false,
    // 搜索按钮
    geocoder: false,
    // home按钮
    homeButton: false,
    // 控制查看器显示模式
    sceneModePicker: false,
    // 是否显示涂层选择器
    baseLayerPicker: false,
    // 是否显示动画控件
    animation: false,
    // 是否显示帮助按钮
    navigationHelpButton: false,
    // 全屏按钮
    fullscreenButton: false,
    // 是否显示VR控件
    // vrButton:false,
    // 是否显示时间轴控件
    timeline: false,
    // 设置天空盒子
    skyBox: new Cesium.SkyBox({
      sources: {
        positiveX: require('@/assets/SkyBox/px.png'),
        negativeX: require('@/assets/SkyBox/nx.png'),
        positiveY: require('@/assets/SkyBox/ny.png'),
        negativeY: require('@/assets/SkyBox/py.png'),
        positiveZ: require('@/assets/SkyBox/pz.png'),
        negativeZ: require('@/assets/SkyBox/nz.png'),
      }
    }),
    // 控制默认地图显示
    imageryProvider: false
  })

  // 隐藏logo
  viewer.cesiumWidget.creditContainer.style.display = 'none'
  // 加载高德底图
  const gaodeImageryProvider = new Cesium.UrlTemplateImageryProvider({
    url: 'https://webrd0{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}',
    subdomains: ['1', '2', '3', '4'],
    credit: '高德地图'
  })

  // 将高德底图添加到viewe中
  viewer.imageryLayers.addImageryProvider(gaodeImageryProvider)

  const gaodeImageryProvider1 = new Cesium.UrlTemplateImageryProvider({
    url: 'https://webst0{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=6&x={x}&y={y}&z={z}',
    layer: 'tianDiTu',
    style: 'default',
    format: 'png',
    credit: '高德地图',
    options: 0.5,
    subdomains: ['1', '2', '3', '4'],
  })

  const layer2 = viewer.imageryLayers.addImageryProvider(gaodeImageryProvider1)
  layer2.alpha = 0.5


  // 叠加国界服务
  var iboMap = new Cesium.UrlTemplateImageryProvider({
    url: tdtUrl + 'DataServer?T=ibo_w&x={x}&y={y}&l={z}&tk=' + token,
    subdomains: subdomains,
    tilingScheme: new Cesium.WebMercatorTilingScheme(),
    maximumLevel: 10
  });
  viewer.imageryLayers.addImageryProvider(iboMap);




})

</script>

<style>
* {
  margin: 0;
  padding: 0;
}

#cesiumContainer {
  width: 100vw;
  height: 100vh;
}
</style>
